import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components'

import './index.scss'

class Channel extends Component {
  constructor(props) {
    super(props)
    this.state = {}
  }

  handleLink (path) {
    if (path) {
      Taro.navigateTo({
        url: path
      })
    }
  }
  
  render() { 
    return (
      <View className='channels'>
        {
          this.props.channels.map((item, index) => {
            return (
              <View
                key={item + index}
                className='items'
                onClick={this.handleLink.bind(this, item.path)}
              >
                <View className='items-img'>
                  <Image src={item.imgSrc} className='img-src' />
                </View>
                <Text>{item.text}</Text>
              </View>
            )
          })
        }
      </View>
    )
  }
}

Channel.defaultProps = {
  channels: []
}
 
export default Channel
